Fix davidson-harel layout crash on graphs > 1024 nodes (#362)#373
Open
AllenLarocque wants to merge 1 commit into
Open
Fix davidson-harel layout crash on graphs > 1024 nodes (#362)#373AllenLarocque wants to merge 1 commit into
AllenLarocque wants to merge 1 commit into
Conversation
heat_tree(layout = "davidson-harel") errored with "The value <x> is not representable as an integer. Invalid value" from igraph whenever a connected component of the graph exceeded 1024 nodes. igraph::layout_with_dh() requires an integer `fineiter`, but layout_functions() computed it as `max(10, log2(vcount(graph))) * effort`. `log2(vcount)` is non-integer once vcount > 1024 (2^10), so igraph rejected it. Round `fineiter` (and `maxiter`, defensively for non-integer `effort`) to integers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #362. It turns out AI can figure out stuff that I can't :)
Problem
heat_tree(..., layout = "davidson-harel")errors on larger graphs:Root cause
igraph::layout_with_dh()requires an integerfineiter. Inlayout_functions()(R/heat_tree--layouts.R) it is computed as:log2(vcount)becomes non-integer as soon as a (connected component of the) graph exceeds 1024 nodes (2^10) — e.g.log2(1598) ≈ 10.64, the exact value in the error. igraph then rejects it. This is why the crash is size-dependent: small graphs (and forests of small components, which metacoder lays out per-component) stay under the threshold, while a single large connected tree trips it.Fix
Round
fineiterto an integer (andmaxiter, defensively, in caseeffortis non-integer). Behaviour is unchanged below 1024 nodes; above it, the layout now runs instead of erroring.Verification
igraph::layout_with_dh(g, fineiter = log2(vcount(g)))reproduces the error on a >1024-node graph;fineiter = round(...)succeeds.heat_tree(layout = "davidson-harel")renders a real ~1,500-node taxonomic tree that previously crashed.Reported by several users over the last few years in #362 — hopefully this unblocks them.
🤖 Generated with Claude Code